package com.yugao.fintech.antelope.system.manager;

import com.yugao.fintech.antelope.common.datasource.AppDeleteMQ;
import com.yugao.fintech.antelope.system.model.ResourceSyncMQ;
import com.yugao.fintech.antelope.system.model.entity.RamModule;
import com.yugao.fintech.antelope.system.model.entity.SysTenant;
import com.yugao.fintech.antelope.system.model.mq.TenantDeleteMQ;
import com.yugao.fintech.antelope.system.model.mq.TenantUpdateMQ;
import com.yugao.fintech.antelope.system.model.mq.UserDeleteMQ;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.stereotype.Component;

import java.util.List;


@Component
public class SysMqManager {
    @Autowired
    private RabbitTemplate rabbitTemplate;

    /**
     * 发送资源模块刷新消息
     */
    public void sendResourceModuleRefresh(List<RamModule> list) {
        rabbitTemplate.convertAndSend(
                ResourceSyncMQ.EXCHANGE, ResourceSyncMQ.KEY_NOTICE_REFRESH, new ResourceSyncMQ(list).toMessage()
        );
    }


    /**
     * 发出删除应用消息
     */
    public void sendDeleteAppMsg(Long appId) {
        AppDeleteMQ mq = AppDeleteMQ.build(appId);
        rabbitTemplate.convertAndSend(AppDeleteMQ.EXCHANGE, AppDeleteMQ.KEY, mq.toMessage());
    }

    /**
     * 发出删除用户消息
     */
    public void sendDeleteUserMsg(Long userId) {
        UserDeleteMQ mq = UserDeleteMQ.build(userId);
        rabbitTemplate.convertAndSend(UserDeleteMQ.EXCHANGE, UserDeleteMQ.KEY, mq.toMessage());
    }

    /**
     * 发出删除租户消息
     */
    public void sendDeleteTenantMsg(Long tenantId) {
        TenantDeleteMQ mq = TenantDeleteMQ.build(tenantId);
        rabbitTemplate.convertAndSend(TenantDeleteMQ.EXCHANGE, TenantDeleteMQ.KEY, mq.toMessage());
    }

    /**
     * 发出更新租户消息
     */
    public void sendUpdateTenantMsg(SysTenant tenant) {
        TenantUpdateMQ mq = TenantUpdateMQ.build(tenant.getId(), tenant.getPackageId(), tenant.getDomain());
        rabbitTemplate.convertAndSend(TenantUpdateMQ.EXCHANGE, TenantUpdateMQ.KEY, mq.toMessage());
    }
}
